#include "log.hpp"

Log::Log(FString path)
{
	if((file = open(path.data(), O_WRONLY|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR))<0)
	{
		cout << "Cannot open log file" << endl;
	}
}

Log::~Log()
{
	close(file);
}

void Log::logger(FString data)
{
	FString str = dateLog();
	str.erase(str.size()-1, 1);
	
	str += "\t";
	str += data;
	str += " \n";
	write(file, str.data(), str.size());
}

FString Log::dateLog()
{
	time_t t = time(NULL);
	char *dateLogs = asctime(localtime(&t));
	return FString(dateLogs);
}
